#include "vlc_player.h"
#include <QDebug>
#include <QFileDialog>
#include <QInputDialog>
#include <QPushButton>
#include <QVBoxLayout>
#include <VLCQtCore/Audio.h>
#include <VLCQtCore/Common.h>
#include <VLCQtCore/Instance.h>
#include <VLCQtCore/Media.h>
#include <VLCQtCore/MediaPlayer.h>
#include <VLCQtWidgets/WidgetVideo.h>
#include "vodlistwgt.h"

VLC_Player::VLC_Player(QWidget *parent)
    : QWidget(parent)
    ,_media(nullptr)
    ,curUrl("")
{
    setFixedSize(300,500);
    QVBoxLayout* layout=new QVBoxLayout(this);

    //创建新窗口
    _video=new VlcWidgetVideo(this);
    _vlcInstance=new VlcInstance(VlcCommon::args(),this);
    _player=new VlcMediaPlayer(_vlcInstance);
    _audio=new VlcAudio(_player);

    //设置默认音量大小
    _audio->setVolume(50);
    _player->setVideoWidget(_video);
    _video->setMediaPlayer(_player);

    //连接vlcmediaplayer的timechanged，更新进度条
    connect(_player,&VlcMediaPlayer::timeChanged,this,[this](int value){
        emit TimeChanged(value);
    });

    _vodlistWgt =new vodlistWgt(this);
    //创建窗口分割器
    _spliter=new QSplitter(Qt::Horizontal,this);
    _spliter->addWidget(_video);
    _spliter->addWidget(_vodlistWgt);
    //设置窗口占比
    int totalWidth=width();
    _spliter->setSizes({totalWidth *4 / 5,totalWidth / 5});

    //将分割器添加到主布局
    layout->addWidget(_spliter);
    setLayout(layout);
}
//vlc_qt库
VLC_Player::~VLC_Player()
{
    delete _audio;
    delete _player;
    delete _media;
    delete VlcInstance;
}

void VLC_Player::OpenUrl(const QString url)
{

}

void VLC_Player::onParsedChanged(bool status)
{

}

void VLC_Player::onBuffeing(float newCache)
{

}

void VLC_Player::HandleCantroSignal(const QVariant &data)
{

}
